<?php
/**
 * 内容管理
 * @author tangbl
 *
 */
class ContentAction extends CommonAction{
	
	/**
	 * 文章列表
	 */
	public function article(){

		if(IS_AJAX){
		
			$data['table']	   = 'Article';
			$data['orderDesc'] = $this->_param('orderDirection','trim','desc');
			$data['orderName'] = $this->_param('orderName','trim','sort');
			$data['pageNum']   = $this->_param('pageNum','intval',C('PAGE_NUMS'));
			$data['nowPage']   = $this->_param('p','intval',1);
			
			$data['where'] = $_POST['where'];
			if(!isset($data['where']['isdel'])){
				$data['where']['isdel'] = 2;
			}
			$data['where'] = array_filter($data['where']);
		
			$json  = sendRest('BDC/Content/contentList', $data, 'post');
			$count = $json['data']['count'];
			$list  = $json['data']['list'];
			$total = ceil($count/$data['pageNum']);
			
			$jsonData  = array('page'=>$data['nowPage'],'total'=>$count,'rows'=>array(),'totalPage'=>$total);
			foreach($list AS $row){
				$entry = array('id'=>$row['id'],
					'cell'=>array(
						'id'       => $row['id'],
						'title'    => $row['title'],
						'sort'     => $row['sort'],
						'lang'     => $row['lang'],
						'addtime'  => date('Y-m-d',$row['addtime']),
						'checked'  => $row['checked'] == 1 ? '是' : '否',
						'lang'	   => $row['lang'],
					),
				);
				$jsonData['rows'][] = $entry;
			}
			$this->ajaxReturn($jsonData,'JSON');
				
		}else{
				
			$this->display();
		}
	}
	
	/**
	 * 添加文章
	 */
	public function articleAdd(){

		if(IS_POST){
			
			$data['lang'] = getLang();
			$data = $_POST;
			$data['table'] = 'Article';
			$data['image'] = array('single'=>array('single'));
			$json = sendRest('BDC/Content/contentAdd',$data,'post');
			
			$this->ajaxReturn($json);
			
		}else{
			$this->display();
		}
	}
	
	/**
	 * 修改文章
	 */
	public function articleEdit(){
		
		$id	= $this->_param('id', 'intval', 0);
		$data['table'] = 'Article';
		$data['image'] = array('single'=>array('single'));
 
		if(IS_POST){
					
			$data = array_merge($data,$_POST);
			$json =	sendRest('BDC/Content/contentEdit', $data, 'post');
			$this->ajaxReturn($json);
			
		}else{
			
			$data['id']	= $id;
			$article	= sendRest('BDC/Content/contentDetail', $data);
			
			$this->assign('detail', $article['data']);
			$this->assign('single', $article['data']['image']['single']['single']);
			$this->display();
		}
	}
	
	/**
	 * 删除文章
	 * @param string $table 内容表名
	 * @param int    $isdel 物理删除:1|逻辑删除0  
	 */
	public function articleDel(){
		
		$data['id'] = $this->_param("id" ,"intval",0);
		$data['table'] = 'Article';
		$data['isdel'] = 0;
		
		$flag  = sendRest('BDC/Content/contentDel', $data);
		$this->ajaxReturn($flag);
	}
	

	/**
	 * 批量审核文章
	 */
	
	public function articleChecked(){
		
		if(IS_AJAX){
			
			$data['table'] = 'Article';
			$data['id']    = $this->_param('id','trim');
			$data['value'] = $this->_param('checked');
			$data['field'] = 'checked';
			
			$flag  = sendRest('BDC/Content/check', $data);
			$this->ajaxReturn($flag);
		}
	}

	
	/**
	 * 批量删除文章
	 */
	public function articleMoreDel(){
		
		if(IS_POST){
			
			$data['table'] = 'Article';
			$data['id']    = $this->_param('id','trim');
			$data['value'] = 1;
			$data['field'] = 'isdel';
			
			$flag  = sendRest('BDC/Content/batch', $data);
			$this->ajaxReturn($flag);
		}
	}

	/**
	 * 广告列表
	 */
	public function admarket(){

		if(IS_AJAX){
		
			$data['table']	   = 'Admarket';
			$data['orderDesc'] = $this->_param('orderDirection','trim','desc');
			$data['orderName'] = $this->_param('orderName','trim','sort');
			$data['pageNum']   = $this->_param('pageNum','intval',C('web_admin_pagenum'));
			$data['nowPage']   = $this->_param('p','intval',1);
			
			$data['where'] = $_POST['where'];
			if(!isset($data['where']['isdel'])){
				$data['where']['isdel'] = 2;
			}
			$data['where'] = array_filter($data['where']);
		
			$json  = sendRest('BDC/Content/contentList', $data, 'post');
			$count = $json['data']['count'];
			$list  = $json['data']['list'];
			$total = ceil($count/$data['pageNum']);
			
			$jsonData  = array('page'=>$data['nowPage'],'total'=>$count,'rows'=>array(),'totalPage'=>$total);
			foreach($list AS $row){
				$entry = array('id'=>$row['id'],
					'cell'=>array(
						'id'       => $row['id'],
						'title'    => $row['title'],
						'sort'     => $row['sort'],
						'addtime'  => date('Y-m-d',$row['addtime']),
						'checked'  => $row['checked'] == 1 ? '是' : '否',
						'lang'	   => $row['lang'],
					),
				);
				$jsonData['rows'][] = $entry;
			}
			$this->ajaxReturn($jsonData,'JSON');
				
		}else{
				
			$this->display();
		}
	}
	/**
	 * 添加广告
	 */
	public function admarketAdd(){

		if(IS_POST){

			$data = $_POST;
			$data['table'] = 'Admarket';
			$data['image'] = array('single'=>array('single'));
			$json = sendRest('BDC/Content/contentAdd',$data,'post');

			$this->ajaxReturn($json, 'JSON');

		}else{
			$this->display();
		}
	}
	/**
	 * 修改广告
	 */
	public function admarketEdit(){
			
		$id	= $this->_param('id', 'intval', 0);
		$data['table'] = 'Admarket';
		$data['image'] = array('single'=>array('single'));

		if(IS_POST){
					
			$data = array_merge($data,$_POST);
			$json =	sendRest('BDC/Content/contentEdit', $data, 'post');
			$this->ajaxReturn($json);
			
		}else{
			
			$data['id']	= $id;
			$article	= sendRest('BDC/Content/contentDetail', $data);
			
			$this->assign('detail', $article['data']);
			$this->assign('single', $article['data']['image']['single']['single']);
			$this->display();
		}
	}

	/**
	 * 删除广告
	 */
	public function admarketDel(){
	
		
		$data['id'] = $this->_param("id" ,"intval",0);
		$data['table'] = 'Admarket';
		$data['isdel'] = 0;
		
		$flag  = sendRest('BDC/Content/contentDel', $data);
		$this->ajaxReturn($flag);
	}
	
	
	/**
	 * 批量审核广告
	 */
	
	public function admarketChecked(){
		
		if(IS_POST){
			
			$data['table'] = 'Admarket';
			$data['id']    = $this->_param('id','trim');
			$data['value'] = $this->_param('checked');
			$data['field'] = 'checked';
			
			$flag  = sendRest('BDC/Content/batch', $data);
			$this->ajaxReturn($flag);
		}
	}

	/**
	 * 批量删除广告
	 */
	
	
	public function admarketMoreDel(){
			
		if(IS_POST){
			
			$data['table'] = 'Admarket';
			$data['id']    = $this->_param('id','trim');
			$data['value'] = 1;
			$data['field'] = 'isdel';
			
			$flag  = sendRest('BDC/Content/batch', $data);
			$this->ajaxReturn($flag);
		}
	}
	
	
	/**
	 * 单页列表
	 */
	public function artonce(){

		if(IS_AJAX){
		
			$data['table']	   = 'Artonce';
			$data['orderDesc'] = $this->_param('orderDirection','trim','desc');
			$data['orderName'] = $this->_param('orderName','trim','sort');
			$data['pageNum']   = $this->_param('pageNum','intval',C('web_admin_pagenum'));
			$data['nowPage']   = $this->_param('p','intval',1);
				
			$data['where'] = $_POST['where'];
			
			if(!isset($data['where']['isdel'])){
				$data['where']['isdel'] = 2;
			}
			$data['where'] = array_filter($data['where']);

		
			$json  = sendRest('BDC/Content/contentList', $data, 'post');
			$count = $json['data']['count'];
			$list  = $json['data']['list'];
			$total = ceil($count/$data['pageNum']);
				
			$jsonData  = array('page'=>$data['nowPage'],'total'=>$count,'rows'=>array(),'totalPage'=>$total);
			foreach($list AS $row){
				$entry = array('id'=>$row['id'],
					'cell'=>array(
						'id'       => $row['id'],
						'title'    => $row['title'],
						'sort'     => $row['sort'],
						'addtime'  => date('Y-m-d',$row['addtime']),
						'checked'  => $row['checked'] == 1 ? '是' : '否',
						'lang'	   => $row['lang'],
					),
				);
				$jsonData['rows'][] = $entry;
			}
			$this->ajaxReturn($jsonData,'JSON');
		
		}else{
		
			$this->display();
		}
	}
	
	/**
	 * 添加单页
	 */
	public function artonceAdd(){

		if(IS_POST){
			
			$data['lang'] = getLang();
			$data = $_POST;
			$data['table'] = 'Artonce';
			$data['image'] = array('single'=>array('single'));
			$json = sendRest('BDC/Content/contentAdd',$data,'post');
				
			$this->ajaxReturn($json, 'JSON');
		}else{
			$this->display();
		}
	}
	
	/**
	 * 修改单页
	 */
	public function artonceEdit(){
				
		$id	= $this->_param('id', 'intval', 0);
		$data['table'] = 'Artonce';
		$data['image'] = array('single'=>array('single'));

		if(IS_POST){
					
			$data = array_merge($data,$_POST);
			$json =	sendRest('BDC/Content/contentEdit', $data, 'post');
			$this->ajaxReturn($json);
			
		}else{
			
			$data['id']	= $id;
			$article	= sendRest('BDC/Content/contentDetail', $data);
			
			$this->assign('detail', $article['data']);
			$this->assign('single', $article['data']['image']['single']['single']);
			$this->display();
		}
	}
	
	/**
	 * 删除单页
	 */
	public function artonceDel(){

		$data['id'] = $this->_param("id" ,"intval",0);
		$data['table'] = 'Artonce';
		$data['isdel'] = 0;
		
		$flag  = sendRest('BDC/Content/contentDel', $data);
		$this->ajaxReturn($flag);
	}
	
	
	/**
	 * 批量审核单页
	 */
	
	public function artonceChecked(){
			
		if(IS_AJAX){
			
			$data['table'] = 'Artonce';
			$data['id']    = $this->_param('id','trim');
			$data['value'] = $this->_param('checked');
			$data['field'] = 'checked';
			$flag  = sendRest('BDC/Content/check',  $data);
			$this->ajaxReturn($flag);
		}
	}
	
	/**
	 * 批量删除单页
	 */
	
	
	public function artonceMoreDel(){
			
		if(IS_POST){
			
			$data['table'] = 'Artonce';
			$data['id']    = $this->_param('id','trim');
			$data['value'] = 1;
			$data['field'] = 'isdel';
			
			$flag  = sendRest('BDC/Content/batch', $data);
			$this->ajaxReturn($flag);
		}
	}
	
	/**
	 * 链接列表
	 */
	public function flink(){
	
		if(IS_AJAX){
	
			$data['table']	   = 'Flink';
			$data['orderDesc'] = $this->_param('orderDirection','trim','desc');
			$data['orderName'] = $this->_param('orderName','trim','sort');
			$data['pageNum']   = $this->_param('pageNum','intval',C('web_admin_pagenum'));
			$data['nowPage']   = $this->_param('p','intval',1);
				
			$data['where'] = $_POST['where'];
			if(!isset($data['where']['isdel'])){
				$data['where']['isdel'] = 2;
			}
			$data['where'] = array_filter($data['where']);
	
			$json  = sendRest('BDC/Content/contentList', $data, 'post');
			$count = $json['data']['count'];
			$list  = $json['data']['list'];
			$total = ceil($count/$data['pageNum']);
				
			$jsonData  = array('page'=>$data['nowPage'],'total'=>$count,'rows'=>array(),'totalPage'=>$total);
			foreach($list AS $row){
				$entry = array('id'=>$row['id'],
						'cell'=>array(
								'id'       => $row['id'],
								'title'    => $row['title'],
								'sort'     => $row['sort'],
								'addtime'  => date('Y-m-d',$row['addtime']),
								'checked'  => $row['checked'] == 1 ? '是' : '否',
								'show'     => $row['show']    == 1 ? '是' : '否',
								'lang'	   => $row['lang'],
						),
				);
				$jsonData['rows'][] = $entry;
			}
			$this->ajaxReturn($jsonData,'JSON');
	
		}else{
			$this->display();
		}
	}
	

	/**
	 * 添加链接
	 */
	public function flinkAdd(){
	
		if(IS_POST){

			$data = $_POST;
			$data['table'] = 'Flink';
			$data['image'] = array('single'=>array('single'));
			$json = sendRest('BDC/Content/contentAdd',$data,'post');
			
			$this->ajaxReturn($json);
			
		}else{
			$this->display();
		}
	}
	/**
	 * 修改链接
	 */
	public function flinkEdit(){
		
		$id	= $this->_param('id', 'intval', 0);
		$data['table'] = 'Flink';
		$data['image'] = array('single'=>array('single'));

		if(IS_POST){
					
			$data = array_merge($data,$_POST);
			$json =	sendRest('BDC/Content/contentEdit', $data, 'post');
			$this->ajaxReturn($json);
			
		}else{
			
			$data['id']	= $id;
			$article	= sendRest('BDC/Content/contentDetail', $data);
			
			$this->assign('detail', $article['data']);
			$this->assign('single', $article['data']['image']['single']['single']);
			$this->display();
		}
	}

	/**
	 * 删除链接
	 */
	public function flinkDel(){
	
		
		$data['id'] = $this->_param("id" ,"intval",0);
		$data['table'] = 'Flink';
		$data['isdel'] = 0;
		
		$flag  = sendRest('BDC/Content/contentDel', $data);
		$this->ajaxReturn($flag);
	}
	

	/**
	 * 批量审核链接
	 */
	
	public function flinkChecked(){
			
		if(IS_POST){
			
			$data['table'] = 'Flink';
			$data['id']    = $this->_param('id','trim');
			$data['value'] = $this->_param('checked');
			$data['field'] = 'checked';
			
			$flag  = sendRest('BDC/Content/batch', $data);
			$this->ajaxReturn($flag);
		}
	}
	

	/**
	 * 批量删除广告
	 */
	public function flinkMoreDel(){
				
		if(IS_POST){
			
			$data['table'] = 'Admarket';
			$data['id']    = $this->_param('id','trim');
			$data['value'] = 1;
			$data['field'] = 'isdel';
			
			$flag  = sendRest('BDC/Content/batch', $data);
			$this->ajaxReturn($flag);
		}
	}
}

?>